package cqut.demo.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 记录日志接口(切面的方法)
 * @author wuyoushan
 * @date 2016/12/25.
 */
public class LogRecord {

    private static final Logger logger= LoggerFactory.getLogger(LogRecord.class);

    //前置通知
    public void logBefore(JoinPoint jp)
    {
        System.out.println(System.currentTimeMillis());
        System.out.println("Log before method");
        logger.error("Log before method");
    }

    //后置通知
    public void logAfter(JoinPoint jp)
    {
        System.out.println("Log after method");
        System.out.println(System.currentTimeMillis());
        logger.error("Log after method");
    }

    //环绕通知
    public void logAround(ProceedingJoinPoint joinPoint){
    	System.out.println("环绕通知前");
    	try {
            Object[] args=joinPoint.getArgs();
            Integer id=(Integer)args[0];
			joinPoint.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
    	System.out.println("环绕通知后");
    }
}
